<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="live.pay.ServiceIds"%>
<%@page import="live.api.impl.SanIsMember"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@page import="live.cz.entity.Order"%>
<%@page import="live.common.Format"%>
<%@page import="live.cz.dao.OrderPay"%>
<%@page import="live.common.PostParam"%>
<%@page import="live.pay.SignUtil"%>
<%@page import="live.api.impl.PaySendReqRes"%>
<%@page import="live.common.GetSequence"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Object userId =session.getAttribute("ssoclientagent.user");
if(userId!=null){
	int isMember = new SanIsMember().isMember((String)userId);
	if(isMember==1){
		out.print("<script>");
		out.print("alert('对不起，您不是三生会员，暂不能进行机票预订、手机充值操作!');");
		out.print("location.href='"+basePath+"'");
		out.print("</script>");
	}
else{
Order order = (Order)request.getAttribute("hfitem");
String desc=OrderPay.returnOrderDesc(order);
//一卡通支付
String req_trans_tm=Format.getInstance().dateFormatString(new Date(), "yyyyMMddHHmmss");
String req_trans_seq=GetSequence.getInstance().returnSeqNum();
String amt = String.valueOf((int)(order.getSalePrice()*100));
Map map = new TreeMap();
map.put("service_id",ServiceIds.PRE_AUTH_RES);
map.put("req_org_cd",PostParam.MOBILE_NAME);
map.put("req_trans_tm",req_trans_tm);
map.put("req_trans_seq",req_trans_seq);
map.put("order_id",order.getOrderid());
map.put("seller_id",PostParam.MOBILE_NAME);
map.put("sub_order_flag","N");
map.put("sub_order_num","0");
map.put("order_desc",desc);
map.put("tot_trans_amt",amt);
map.put("buyer_id",(String)userId);
map.put("valid_date","0");
map.put("notify_url",PostParam.MOBILE_NOTIFY);
String sign=SignUtil.sign(map,PostParam.PAYKEY);
map.put("sign",sign);
map.put("sign_type","MD5");
new PaySendReqRes().insertSendRequest(map);
//支付宝支付
//String subject_desc = new OrderPay().returnSubject(order); 
//String paygateway = "https://www.alipay.com/cooperate/gateway.do?"; //支付接口（不可以修改）
//		String service = "create_direct_pay_by_user";//快速付款交易服务（不可以修改）
//		String sign_type = "MD5";//文件加密机制（不可以修改）
//		String out_trade_no = order.getOrderid();//商户网站订单（也就是外部订单号，是通过客户网站传给支付宝，不可以重复）
//		String input_charset = "utf-8";  //（不可以修改）
		//partner和key提取方法：登陆签约支付宝账户--->点击“商家服务”就可以看到
//		String partner = AlipayConfig.partnerID; //支付宝合作伙伴id (账户内提取)
//		String key = AlipayConfig.key; //支付宝安全校验码(账户内提取)
//		String body = desc; //商品描述，推荐格式：商品名称（订单编号：订单编号）
//		String total_fee = order.getSalePrice()+""; //订单总价
//		String payment_type = "1";//支付宝类型.1代表商品购买（目前填写1即可，不可以修改）
//		String seller_email =  AlipayConfig.sellerEmail; //卖家支付宝帐户,例如：gwl25@126.com
//		String subject = subject_desc; //商品名称
//		String show_url = "http://localhost:8080";  //根据集成的网站而定 例如：http://wow.alipay.com
		
//		String path_yu = request.getScheme() + "://" + request.getServerName()
//				+ ":" + request.getServerPort();// "http://190.10.2.33:7001/"; 

//		String notify_url = path_yu + ""; //通知接收URL(本地测试时，服务器返回无法测试)
//		String return_url = path_yu + ""; //支付完成后跳转返回的网址URL
	    //注意以上两个地址 要用 http://格式的完整路径
	    /*以下两个参数paymethod和defaultbank可以选择不使用，如果不使用需要注销，并在Payment类的方法中也要注销*/
	//	String paymethod = request.getParameter("paymethod").trim();//赋值:bankPay(网银);cartoon(卡通); directPay(余额)
	//	String defaultbank = request.getParameter("defaultbank").trim();
		//ICBCB2C	中国工商银行
		//CMB		招商银行
		//CCB		中国建设银行
		//ABC		中国农业银行
		//SPDB		上海浦东发展银行
		//SPDBB2B	上海浦东发展银行(B2B)
		//CIB	兴业银行
		//GDB		广东发展银行
		//SDB	深圳发展银行
		//CMBC		中国民生银行
		//COMM		交通银行
		//POSTGC		邮政储蓄银行
		//CITIC		中信银行
		//CCBVISA	建行VISA
		//VISA		VISA
	    
	//	String ItemUrl = Payment.CreateUrl(paygateway, service, sign_type,
	//			out_trade_no, input_charset, partner, key, show_url, body,
	//			total_fee, payment_type, seller_email, subject, notify_url,
	//			return_url);
%>
<%if(request.getParameter("chargeType")==null){ %>
<jsp:include page="../pub_head.jsp">
<jsp:param value="4" name="type"/>
</jsp:include>
<%}else{ %>
<jsp:include page="../pub_head.jsp">
<jsp:param value="5" name="type"/>
</jsp:include>
<%} %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath %>">
    <title>话费充值</title>
    <META content="text/html; charset=UTF-8" http-equiv="Content-Type">
	<META http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
	<meta http-equiv="Pragma" content="no-cache">
	<script type="text/javascript" src="script/jquery-1.3.1.js"></script>
	<LINK  media="all" href="css/global.css" type="text/css" rel="stylesheet"/>
	<LINK media="all" href="css/tickets.css" type="text/css" rel="stylesheet"/>
	<link rel="stylesheet" type="text/css" href="hfcz/css/charging.css" />
<style> 
.rbox-bg{background: url("hfcz/css/bg-form-middle.jpg") repeat-y; width: 750px;}
.rbox-top{background: url("hfcz/css/bg-form-top.jpg") no-repeat left top; width: 750px;}
.rbox-bottom{background: url("hfcz/css/bg-form-bottom.jpg") no-repeat left bottom;padding:20px 18px 20px;zoom: 1; width: 750px;}
.rbox-border{border: 1px solid #5d8eaf; width: 712px;}
</style>
  </head>
  
  <body>
   <div class="wrapper clearfix">
   <div class="stepout shouji">
   <H1>话费充值</H1>

    <ul>

      <li class="current">填写充值信息</li>

      <li class="current">支付</li>

      <li>完成</li>

    </ul>
  </div>
  <div>
<div class="rbox"> 
<div class="rbox-bg">
<div class="rbox-top">
<div class="rbox-bottom">
<div class="rbox-border"> 
<div class="telephone tel-form">
<%--<input type="hidden" name="<%=Constants.TOKEN_KEY%>"    value="<%=session.getAttribute(Globals.TRANSACTION_TOKEN_KEY)%>"/>--%>
<div style="width:auto; margin-left:70px;"><br/><font color="red">
	请确认充值号码无误后进行付款，如因号码错误仍进行充值，造成的损失由用户自行承担！
</font>
</div> 
 <div class="tel-section tel-num">
<label class="tel-section-title" for="J_TelInput">充值号码：</label>
<div class="tel-section-field">
					<div class="tel-num-wrapper" id="J_TelInputBox">
                       <b>${hfitem.phonenum }</b>
					</div>
				</div>
</div>
<div class="tel-section tel-num">
<label class="tel-section-title" for="J_TelInput">充值面额：</label>
<div class="tel-section-field">
					<div class="tel-num-wrapper" id="J_TelInputBox">
                       <b>￥<fmt:formatNumber value="${hfitem.proPrice}" pattern="#"></fmt:formatNumber>元</b>
					</div>
				</div>
</div>
<div class="tel-section tel-num">
<label class="tel-section-title" for="J_TelInput">支付金额：</label>
<div class="tel-section-field">
					<div class="tel-num-wrapper" id="J_TelInputBox">
                       <b style="color: red">￥<fmt:formatNumber value="${hfitem.salePrice}" pattern="#.##"></fmt:formatNumber>元</b>
					</div>
				</div>
</div>
<div class="tel-buy with-ad" id="J_TelBuyPanel">
	<button class="tel-submit" id="J_TelSubmitBtn" onclick="startpay()" hidefocus="true">立即支付</button>
	<br/>
</div>
<form name="pform" id="pform" action="<%=PostParam.PAY_API %>" method="post" target="_blank">
    	<input type="hidden" name="service_id" value="<%=ServiceIds.PRE_AUTH_RES%>"/>
    	<input type="hidden" name="req_org_cd" value="<%=PostParam.MOBILE_NAME%>"/>
    	<input type="hidden" name="req_trans_tm" value="<%=req_trans_tm %>"/>
    	<input type="hidden" name="req_trans_seq" value="<%=req_trans_seq%>"/>
    	<input type="hidden" name="order_id" value="<%=order.getOrderid() %>"/>
    	<input type="hidden" name="seller_id" value="<%=PostParam.MOBILE_NAME %>"/>
    	<input type="hidden" name="sub_order_flag" value="N"/>
    	<input type="hidden" name="sub_order_num" value="0"/>
    	<input type="hidden" name="order_desc" value="<%=desc%>"/>
    	<input type="hidden" name="tot_trans_amt" value="<%=amt%>"/>
    	<input type="hidden" name="buyer_id" value="<%=(String)userId %>"/>
    	<input type="hidden" name="valid_date" value="0"/>
    	<input type="hidden" name="notify_url" value="<%=PostParam.MOBILE_NOTIFY %>"/>
    	<input type="hidden" name="sign" value="<%=sign %>"/>
    	<input type="hidden" name="sign_type" value="MD5"/>
    </form>
</div>
</div></div></div></div> 
</div></div>
<div id="conver"></div>
<div id="loading" style="display:none; border: solid 10px #247FB6;background-color: #FFFFFF; text-align: center;" align="center">
	<div style="height: 90px; border: text-align: left; font-family: '宋体'; " align="center" >
		<span style="float: left;margin: 10px">
			<img src="/images/bg-sys-icon-info.gif" />
		</span>
	<p>&nbsp;</p>
	<p><label style="font-size: 16px;text-align: left;">请在新打开页面内完成支付</label></p>
	<p>&nbsp;</p>
	<p><label style="font-size: 14px;">付款完成前请不要关闭此窗口</label></p>
	</div>
	<p style="vertical-align: bottom; position: relative; margin-top: 10px;">
    <button onclick="javascript:torecon()" style="height:40px; padding:5px; font-size: 14px;font-weight:'bolder'; border:solid; " id="recon">已完成支付</button>
    <!-- <button style="height:40px; border:solid; margin-left:30px; padding:5px; cursor:pointer; font-weight:bolder; font-size: 14px; background-color: #247FB6; color: white;">已完成支付</button> -->
    </p>
</div>
<script type="text/javascript">
<!--
  	var secs = 9;
	var wait = secs * 1000;  	
	function popDiv(){
	var windowWidth = document.documentElement.offsetWidth;
	var windowHeight = document.documentElement.offsetHeight;
	$('#loading').css({
                    background: '#fff',
                    zIndex: 3000,
                    padding: '10px',
                    width: '300px',
                    height: '140px',
                    margin: '0 auto',
                    opacity: 1,
                    position: 'absolute',
                    top: windowHeight/2-134,
                    left: windowWidth/2-172
                  });
   	  $('#recon').css({ background: 'none',color:'gray'}).text('已完成支付 ('+secs+')').attr('disabled',true);
	    for(i = 1; i <= secs; i++)
         {window.setTimeout("upTime(" + i + ")", i * 1000);}
     	 $('#conver').css({
         	height:document.documentElement.clientHeight,
         	width:document.documentElement.scrollWidth,
         	position: 'absolute',
         	margin:'0',
         	padding:'0',
         	left:'0px',
         	top:'0px',
         	opacity: '0.6',
         	zIndex: 2000,
         	background: '#ccc'
         });
     	$('#loading').show();
     }
     
     function upTime(num){
     	if(num<secs)
     	{$('#recon').text('已完成支付 ('+((wait/1000)-num)+')');}
     	else{
     		$('#recon').css({background:'#247FB6',color: 'white',cursor:'pointer'}).attr('disabled',false);
     		$('#recon').text('已完成支付');
     	}
     }
    function torecon(){
    	$('form').first().attr('action','/recon.do').attr('target','_parent').submit();
    }
//-->
</script>
<script type="text/javascript">
<!--
function removeButtonBind(){
	$("#J_TelSubmitBtn").removeClass("tel-submit");
	$("#J_TelSubmitBtn").addClass("tel-submit-lock");
	$("#J_TelSubmitBtn").unbind("click");
	$("#J_TelSubmitBtn").attr("disabled","disabled");
}

function aliStartPay(){
$('#alipay').attr('href','javascript:void(0)');
	removeButtonBind();
}
function startpay(){
removeButtonBind();
	/*$.ajax({type:"POST",url:"/hfcz/new.do"
	,
	async:false,
	success:function(data){
		if(parseInt(data)==1){*/
		$('form:first').submit();
			popDiv();
		/*}
		else if(parseInt(data)==-1){
			alert('当前网络缓慢，请稍候重试……');
			location.href="${chargeType==null?'/hfcz':'/hfcz/tel.jsp'}";		
		}
		else if(parseInt(data)==-2){
			alert('您的订单已提交，10S内不得对同一号码进行充值');
		}else if(parseInt(data)==-3){
			alert('当前数据已过期，请重试……');
			location.href="${chargeType==null?'/hfcz':'/hfcz/tel.jsp'}";
		}
	}
	});*/
}
function recon(){
var oriSerId=$("input[name='service_id']").val();
var orderId=$("input[name='order_id']").val();
var seqNum=$("input[name='req_trans_seq']").val();
location.href='/recon.do?service_id='+oriSerId+'&order_id='+orderId+'&original_trans_seq='+seqNum+'&type=mobile';
}
//-->
</script>
 <%@include file="../footer.jsp" %>
<%}} %>
</div>
  </body>
</html>
